package com.rimi.bbs.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.rimi.bbs.bean.Card;
import com.rimi.bbs.service.CardService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 项目通用跳转页面控制层
 */
@Controller
public class PageController {

    private Logger logger= LoggerFactory.getLogger(getClass());

    @Autowired
    private CardService cardService;

    //一级
    @GetMapping("{page}.html")
    public String page(@PathVariable String page){
        return page;
    }

    //二级目录
    @GetMapping("/{dir}/{page}.html")
    public String page2(@PathVariable String dir, @PathVariable String page, Model model){
        model.addAttribute("page",dir);
        logger.info("pageType----:"+dir+"/"+page);
        model.addAttribute("pageType","/"+dir+"/"+page);
        return "/"+dir+"/"+page;
    }

    //三级目录
    @GetMapping("/{dir}/{dir2}/{page}.html")
    public String page3(@PathVariable String dir,@PathVariable String dir2, @PathVariable String page, Model model){
        model.addAttribute("page",dir);
        return "/"+dir+"+"+dir2+"/"+page;
    }


    /**
     * @return
     * 首页跳转
     */
    @RequestMapping("/index")
    public String index(Model model){
        IPage<Card> cardList = cardService.getCardList(null, 1, 10);
        model.addAttribute("cardList",cardList.getRecords());
        model.addAttribute("",cardList.getCurrent());
        model.addAttribute("cardTypeId",0);
        model.addAttribute("technicalClass",0);
        return "index";
    }
    /**
     * @return
     * 首页跳转
     */
    @RequestMapping("/")
    public String indexPage(){
        return "redirect:/index";
    }

    /**
     * @return
     * 首页跳转
     */
    @RequestMapping("")
    public String indexPage2(){
        return "redirect:/index";
    }


}
